//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    motto: 'Hello World',
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),

  },
  //事件处理函数
  bindViewTap: function () {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  onLoad: function () {
    var that = this;
    that.startWifi();
    wx.getSystemInfo({
      success: function(res) {
        console.log(res)
        that.setData({
          windowHeight: res.windowHeight,
          windowWidth: res.windowWidth
        })
      },
    })
  },
  startWifi: function () {
    var that = this;
    wx.startWifi({
      success: function (res) {
        console.log('start', res)
        that.getWifiList()
      },
      fail: res => {
        wx.showModal({
          title: '提示',
          content: '未能成功打开WIFI，请退出重新授权',
          showCancel: false
        })
      }
    })
  },
  getWifiList: function () {
    var that = this;
    wx.getWifiList({
      success: function (res) {
        wx.onGetWifiList(function (res) {
          console.log('list2', res)
          that.setData({
            wifiList: res.wifiList
          })
        })
      }
    })
  },
  connectWifi: function () {
    wx.connectWifi({
      SSID: 'CWCC',
      BSSID: 'D8:C8:E9:07:F1:30',
      password: '369258147',
      success: function (res) {
        console.log('end', res)
      }
    })
  },
  scanCode: function () {
    wx.scanCode({
      success: (res) => {
        console.log(res)
      }
    })
  },
  getUserInfo: function (e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  }
})
